from fastapi import APIRouter, Depends

from forward.api.admin.schemas.user import UserListInSchema, UserDetailInSchema, UserEditlInSchema, UserInfoOutSchema
from forward.api.admin.service.user.user import UserService
from forward.http_base import unified_resp
from forward.schema_base import PageInationResult

router = APIRouter(prefix='/user')


@router.get('/list', response_model=PageInationResult[UserInfoOutSchema])
@unified_resp
async def lists(list_in: UserListInSchema = Depends(),
                user_service: UserService = Depends(UserService.instance)):
    """
    用户列表
    :return:
    """
    return await user_service.list(list_in)


@router.get('/detail')
@unified_resp
async def detail(detail_in: UserDetailInSchema = Depends(),
                 user_service: UserService = Depends(UserService.instance)) -> UserInfoOutSchema:
    """
    用户详情
    :return:
    """
    return await user_service.detail(detail_in=detail_in)


@router.post('/edit')
@unified_resp
async def edit(edit_in: UserEditlInSchema,
               user_service: UserService = Depends(UserService.instance)) -> UserInfoOutSchema:
    """
    用户修改
    :return:
    """
    return await user_service.edit(edit_in=edit_in)
